import 'package:favor_cate/core/model/category_model.dart';
import 'package:favor_cate/core/model/meal_model.dart';
import 'package:favor_cate/core/viewmodel/meal_view_model.dart';
import 'package:favor_cate/ui/widgets/meal_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class MealContent extends StatelessWidget {

  final CategoryModel _category;
  MealContent(this._category);

  @override
  Widget build(BuildContext context) {
    return Selector<MealViewModel, List<MealModel>>(
      shouldRebuild: (prev, next) => !listEquals(prev, next),
      builder: (ctx, meals, child) {
        return ListView.builder(
            itemCount: meals.length,
            itemBuilder: (ctx, index) {
              return MealItem(meals[index]);
            }
        );
      },
      selector: (ctx, model) => model.meals.where((element) => element.categories.contains(_category.id)).toList()
    );
  }
}
